! Huistaak 2 TWS
!
! Roel Matthysen
! s0202264
! 1e Master Wiskundige Ingenieurstechnieken
!
!
!
!
!
!
program test_module
    use my_module
    implicit none

    real :: x(10,10)
    integer :: a(10), sel(3)
    integer :: i
    integer, allocatable :: v(:)
    logical :: w



    allocate(v(size(x,2)))

    ! Test play_with_array and show_array
    call init_random_seed()
    call random_number(x)
    call show_array(x)
    call play_with_array(x,v,w)
    print *, 'X na play_with_array'
    call show_array(x)
    print *, 'V na play_with_array'
    call show_array(v)
    print *, 'W na play_with_array'
    print *, w
    

    ! Test integer_hist with random data
    a = int(10*reshape(x,(/10/)))
    print *,'Vector voor random waarden:'
    sel = (/ 1,3,5 /)
    call show_array(a)
    write(unit=*,fmt="(A11,3i4)") "De getallen",sel
    call integer_hist(a,sel)
    write(unit=*,fmt="(A11,3i4,A)") "komen resp.",sel," keer voor"
    

    ! Test integer_hist for sel exceeding values and negative indeces
    a = (/ (i,i=-3,6) /)
    print *,'Vector voor negatieve waarden en te hoge waarden in sel:'
    sel = (/ -4,-3,7 /)
    call show_array(a)
    write(unit=*,fmt="(A11,3i4)") "De getallen",sel
    call integer_hist(a,sel)
    write(unit=*,fmt="(A11,3i4,A)") "komen resp.",sel," keer voor"


    contains
    ! Subroutine for initialising seed taken from gfortran documentation
    SUBROUTINE init_random_seed()
    INTEGER :: i, n, clock
    INTEGER, DIMENSION(:), ALLOCATABLE :: seed

    CALL RANDOM_SEED(size = n)
    ALLOCATE(seed(n))

    CALL SYSTEM_CLOCK(COUNT=clock)

    seed = clock + 37 * (/ (i - 1, i = 1, n) /)
    CALL RANDOM_SEED(PUT = seed)

    DEALLOCATE(seed)
    END SUBROUTINE
    
end program